<?php
/**
 * Created by PhpStorm.
 * User: xiaoe
 * Date: 2018/5/28
 * Time: 15:05
 */

namespace App\Http\Controllers\Api;


use App\ImageIcon;
use App\SubOneIamgeCate;
use Illuminate\Http\Request;

class IconController extends Controller
{
    public function IconCate()
    {
        $list = SubOneIamgeCate::where('id','!=',16)->where('pid',0)->get();

        return $this->response->array([
            'code'=>200,
            'message'=>'ok',
            'data'=>$list
        ]);
    }


    public function IconCateList(Request $request)
    {

        $id = $request->id;
        $list = ImageIcon::with(['image','level2'])->where('level1',$id)->get();

        $list = $list->map(function ($v,$k){
            return [
                'id' => $v->id,
                'name'=>$v->name,
                'image' => $v->image['url'],
                'level2' => $v->level2,
                'catename' => (SubOneIamgeCate::where('id',$v->level2)->first())['name'],
                'desc' => $v->desc,
            ];
        });
        $data = array();
        foreach ($list as $v){
            $data[$v['catename']][] = $v;
        }


        return $this->response->array([
            'code'=>200,
            'message'=>'ok',
            'data'=>$data
        ]);
    }


    public function TrafficPoliceGesture()
    {
        $list = SubOneIamgeCate::where('pid',16)->get();
        $list = $list->map(function ($v,$k){
            return [
                'id' => $v->id,
                'name'=>$v->name,
                'url' => 'Traff/'.$v->id,
            ];
        });
        return $this->response->array([
            'code'=>200,
            'message'=>'ok',
            'data'=>$list
        ]);
    }


    public function TrafficPoliceGestureInfo(Request $request)
    {

        $id = $request->id;
        $list = ImageIcon::where('level2',$id)->first();

        return $this->response->array([
            'code'=>200,
            'message'=>'ok',
            'data'=>$list
        ]);
    }





}